<?php
	$content_id = $params[0];
	if($_SERVER["REQUEST_METHOD"]=='POST') {
		$title			= strip_tags($_POST['title']);
		$detail			= $_POST['detail'];
		$keyword		= keyword($detail);
		$status			= $_POST['status']=='publish' ? '1': '0';
		$ip				= getUserIP();

		$upload_fieldname	= 'thumb';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/news/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_sql = ", `thumb` = '". basename($upload_fullpath) ."'";
		}

		$upload_fieldname	= 'image';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/news/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_sql_image = ", `image` = '". basename($upload_fullpath) ."'";
		}

		$sql = "UPDATE `tbl_news` SET `title` = '$title', `detail` = '$detail', `keyword` = '$keyword' $upload_sql $upload_sql_image , `ip` = '$ip', `status` = '$status' WHERE  `content_id` = '$content_id' LIMIT 1;";
		mysql_query($sql);
		redirect('../');
		exit;
	}

	$sql = "SELECT * FROM `tbl_news` WHERE `content_id` = '$content_id' LIMIT 1";
	$query = mysql_query($sql);
	while($result = mysql_fetch_assoc($query)) {
		$title			= $result['title'];
		$detail			= $result['detail'];
		$thumbHTML		= $result['thumb'] ? "<img src=\"/thumb/195/115/zc/contents/news/{$result['thumb']}\" /><br />": "";
		$imageHTML		= $result['image'] ? "<img src=\"/thumb/560/300/zc/contents/news/{$result['image']}\" /><br />": "";
	}
	mysql_free_result($query);
 
 
	include 'ckeditor/ckeditor.php';
	include 'ckeditor/ckfinder/ckfinder.php';
	
	$ckeditor = new CKEditor();
	$ckeditor->returnOutput			= true;
	$ckeditor->basePath				= '/backend/ckeditor/';
	
	CKFinder::SetupCKEditor($ckeditor, '/backend/ckeditor/ckfinder/');
	$detailHTML = $ckeditor->editor('detail', $detail);
?>